package cc.mrbird.febs.common.configure;

import cc.mrbird.febs.common.entity.PayConstant;
import cc.mrbird.febs.common.exception.RedisConnectException;
import cc.mrbird.febs.monitor.service.IRedisService;
import com.alipay.easysdk.factory.Factory;
import com.alipay.easysdk.kernel.Config;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

/**
 * @ClassName AlipayConfig
 * @Description
 * @Author 狗蛋儿
 * @Date 2020/11/26 13:03
 * @Version V1.0
 **/
@Slf4j
public class PaymentConfig {

    public static PaymentConfig loadConfiguration(IRedisService redisService) throws RedisConnectException {
        Config config = new Config();
        // 网关协议
        config.protocol = redisService.get(PayConstant.SUFFIX + PayConstant.PAY_ALI_PAY_PROTOCOL).trim();
        // 网关地址
        config.gatewayHost = redisService.get(PayConstant.SUFFIX + PayConstant.PAY_ALI_PAY_GATEWAY_HOST).trim();
        // 密钥加密方式
        config.signType = redisService.get(PayConstant.SUFFIX + PayConstant.PAY_ALI_PAY_SIGN_TYPE).trim();
        // 应用识别码APPID
        config.appId = redisService.get(PayConstant.SUFFIX + PayConstant.PAY_ALI_PAY_APP_ID).trim();
        // 应用私钥
        config.merchantPrivateKey = redisService.get(PayConstant.SUFFIX + PayConstant.PAY_ALI_PAY_PRIVATE_KEY).trim();
        // 支付宝公钥
        config.alipayPublicKey = redisService.get(PayConstant.SUFFIX + PayConstant.PAY_ALI_PAY_PUBLIC_KEY).trim();
        Factory.setOptions(config);
        return new PaymentConfig();
    }
}
